package com.running.base.run.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by eslin on 17/1/16.
 * 获取根据环境加载的bean
 */
public class SpringContextsUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;    //Spring应用上下文环境
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextsUtil.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBean(String name) throws BeansException {
        return applicationContext.getBean(name);
    }
}
